/*!
 * Ext JS Library 3.0.3
 * Copyright(c) 2006-2009 Ext JS, LLC
 * licensing@extjs.com
 * http://www.extjs.com/license
 */
Ext.ns('Ext.ux.form');
function allPrpos(obj) {    
    // 用来保存所有的属性名称和值   
    var props = "";   
    // 开始遍历   
    for(var p in obj){    
       // 方法   
       if(typeof(obj[p])=="function"){    
            obj[p]();   
        }else{    
            // p 为属性名称，obj[p]为对应属性的值   
            props+= p + "=" + obj[p] + "\n";   
        }    
    }    
    // 最后显示所有的属性   
    alert(props);   
}  

Ext.ux.form.SearchField = Ext.extend(Ext.form.TwinTriggerField, {
    initComponent : function(){
        Ext.ux.form.SearchField.superclass.initComponent.call(this);
        this.on('specialkey', function(f, e){
            if(e.getKey() == e.ENTER){
                this.onTrigger2Click();
            }
        }, this);
    },

    validationEvent:false,
    validateOnBlur:false,
    trigger1Class:'x-form-clear-trigger',
    trigger2Class:'x-form-search-trigger',
    hideTrigger1:true,
    width:180,
    hasSearch : false,
    paramName : 'query',

    onTrigger1Click : function(){
        if(this.hasSearch){
            this.el.dom.value = '';
            this.store.baseParams = this.store.baseParams || {};
            this.store.baseParams[this.paramName] = '';
			this.store.baseParams['start'] = 0;	
			this.store.baseParams['limit'] = 17;	
            this.store.load({params:this.store.baseParams});
            this.triggers[0].hide();
            this.hasSearch = false;
        }
    },

    onTrigger2Click : function(){
        var v = this.getRawValue();
        if(v.length < 1){
            this.onTrigger1Click();
            return;
        }
        this.store.baseParams = this.store.baseParams || {};
        this.store.baseParams[this.paramName] = v;	
		this.store.baseParams['start'] = 0;	
		this.store.baseParams['limit'] = 17;	
        this.store.load({params:this.store.baseParams});
        this.hasSearch = true;
        this.triggers[0].show();
    }
});